#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Sun Feb  4 17:59:26 2024

@author: ndrach
"""

import sys
# Insert path to advMSplot.py below
# sys.path.append('INSERT PATH HERE')

from advMSplot import *

import pandas as pd

''' 20 nm '''

log_file_path = 'Fig 2/a/20 nm/JAN 23 2018 15-26.log' # log file path for 20 nm data
cdf_file_path = 'Fig 2/a/20 nm/JAN 23 2018 15-26.cdf' # CDF file path for 20 nm data
tsv_file_path = 'Fig 2/a/20 nm/ivpt15.tsv' # ivpt file path for 20 nm data


tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)

scan_start, scan_end = 9000,11000
spec_20 = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)


mz_20 = spec_20[0]
A_20 = spec_20[1]

N = 30
mzsmooth_20 = np.convolve(mz_20,np.ones(N)/N, mode = 'same')
Asmooth_20 = np.convolve(A_20,np.ones(N)/N, mode = 'same')




''' 125 nm '''

log_file_path = 'Fig 2/a/125 nm/FEB 18 2019 15-59.log' # log file path for 125 nm data
cdf_file_path = 'Fig 2/a/125 nm/FEB 18 2019 15-59.cdf' # CDF file path for 125 nm data
tsv_file_path = None # ivpt file path for 125 nm data


# tsv_data = readIVPT(tsv_file_path)
tsv_data = pd.DataFrame()
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)

scan_start, scan_end = 15000,25000
spec_125 = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)


mz_125 = spec_125[0]
A_125 = spec_125[1]

N = 30
mzsmooth_125 = np.convolve(mz_125,np.ones(N)/N, mode = 'same')
Asmooth_125 = np.convolve(A_125,np.ones(N)/N, mode = 'same')



''' 300 nm '''

log_file_path = 'Fig 2/a/300 nm/JAN 29 2019 16-30.log' # log file path for 300 nm data
cdf_file_path = 'Fig 2/a/300 nm/JAN 29 2019 16-30.cdf' # CDF file path for 300 nm data
tsv_file_path = 'Fig 2/a/300 nm/ivpt01.tsv' # ivpt file path for 300 nm data


tsv_data = readIVPT(tsv_file_path)
mz_bins, combined_spec_data = process_cdf_file(cdf_file_path,log_file_path)
combined_data = combineFiles(tsv_data, combined_spec_data, mz_bins)

scan_start, scan_end = 15000,25000
spec_300 = sum_intensity_for_scan_range(combined_data, scan_start, scan_end)


mz_300 = spec_300[0]
A_300 = spec_300[1]

N = 30
mzsmooth_300 = np.convolve(mz_300,np.ones(N)/N, mode = 'same')
Asmooth_300 = np.convolve(A_300,np.ones(N)/N, mode = 'same')

fig, ax = plt.subplots()
ax.plot(mzsmooth_300, Asmooth_300/np.max(Asmooth_300[500:]), color = 'tab:green')
ax.plot(mzsmooth_125, Asmooth_125/np.max(Asmooth_125[500:]), color = 'tab:red')
ax.plot(mzsmooth_20, Asmooth_20/np.max(Asmooth_20[500:]), color = 'tab:blue')


ax.set_xlim(50,375)
ax.set_ylim(0,1.1)
